package test;

import java.io.BufferedReader;
import java.io.FileReader;


import org.junit.Test;

import sqlengine.Main;

public class File {
	
	static int score = 0;

	@Test
	public void executeFile(){
		boolean eCaught = false;
		try {
		    
		    
		    String str;
		    
		    BufferedReader in = new BufferedReader(new FileReader("outputcheck.txt"));
		    Main m = new Main();
		    String out = m.process("@file.sql");
		    String[] lines = out.split("\n");
		    int i = 0;
		    while ((str = in.readLine()) != null) {
		    	if(!str.equals(lines[i++]))
		    		throw new Exception();
		    }
		    in.close();
		    in = new BufferedReader(new FileReader("outputcheck2.txt"));
		    m = new Main();
		    out = m.process("@file2.sql");
		    lines = out.split("\n");
		    i = 0;
		    while ((str = in.readLine()) != null) {
		    	if(!str.equals(lines[i++]))
		    		throw new Exception();
		    }
		    in.close();
		    
		} catch (Exception e) {
			eCaught = true;
		}
		if(!eCaught){
			score+= Breakdown.file;
			SC.score.append("\n\t executing commands from a file works - " + Breakdown.file + "/" + Breakdown.file);
		}else{
			SC.score.append("\n\t executing commands from a file doesn't work - 0/" + Breakdown.file);
		}
	}
	
}
